package cn.nawang.ebeim.api.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.nawang.ebeim.api.domain.StorageVersionTreeToDo;
import cn.nawang.ebeim.api.service.StorageVersionTreeToDoService;
import cn.nawang.ebeim.api.utils.Constant;

/**
 * @ClassName: StorageVersionTreeToDoController
 * @Description: TODO
 * @author fanyb
 * @date Aug 26, 2015 3:00:02 PM
 * @version v1.0
 */
@RestController
public class StorageVersionTreeToDoController {

  private static final Logger LOG = LoggerFactory.getLogger(StorageVersionTreeToDoController.class);

  @Autowired
  private StorageVersionTreeToDoService storageVersionTreeToDoService;

  /**
   * 
   * @author fanyb
   * @Description: 新增
   * @param storageVersionTreeToDo 对象
   * @return Map<String,Object>
   * @date Aug 26, 20154:55:45 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/add", method = RequestMethod.GET)
  public Map<String, Object> add(StorageVersionTreeToDo storageVersionTreeToDo) {
    LOG.debug("/token/storage_version_tree_to_do/add {}", storageVersionTreeToDo);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean addFlag = storageVersionTreeToDoService.add(storageVersionTreeToDo);
    if (addFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("add {}", map);
    return map;
  }

  /**
   * 
   * 
   * @author fanyb
   * @Description: 查找未处理StorageVersionTreeToDo列表
   * @return Map<String,Object>
   * @date Aug 26, 20154:57:06 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/list/untreated", method = RequestMethod.GET)
  public Map<String, Object> findUntreatedList() {
    LOG.debug("/token/storage_version_tree_to_do/list/untreated {}");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    map.put("list", storageVersionTreeToDoService.findUntreatedList());
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findUntreatedList {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 批量删除
   * @param ids 删除id数组
   * @return Map<String,Object>
   * @date Aug 26, 20155:10:37 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/delete/storage_version_tree_to_do_ids", method = RequestMethod.GET)
  public Map<String, Object> delete(String[] storageVersionTreeToDoIds) {
    LOG.debug("/token/storage_version_tree_to_do/delete/storage_version_tree_to_do_ids {}"
        + storageVersionTreeToDoIds);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean deleteFlag = storageVersionTreeToDoService.delete(storageVersionTreeToDoIds);
    if (deleteFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("delete {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 更新
   * @param storageVersionTreeToDo
   * @return Map<String,Object>
   * @date Sep 16, 20152:41:54 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/update", method = RequestMethod.GET)
  public Map<String, Object> update(StorageVersionTreeToDo storageVersionTreeToDo) {
    LOG.debug("/token/storage_version_tree_to_do/update {}", storageVersionTreeToDo);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean updateFlag = storageVersionTreeToDoService.update(storageVersionTreeToDo);
    if (updateFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("update {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 判断storageVersionTreeTodo是否存在
   * @param storageCloudId
   * @param datasourceId
   * @param version
   * @return Map<String,Object>
   * @date Sep 16, 20155:46:41 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/is_exist", method = RequestMethod.GET)
  public Map<String, Object> isExistStorageFileToDo(String storageCloudId, String datasourceId,
      String version) {
    LOG.debug("/token/storage_version_tree_to_do/is_exist {}", storageCloudId, datasourceId,
        version);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean existFlag = storageVersionTreeToDoService.isExistStorageVersionTreeToDo(storageCloudId,
        datasourceId, version);
    map.put("message", existFlag);
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("isExistStorageFileToDo {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 根据数据源编号和版本号查找StorageVersionTreeToDo对象
   * @param datasourceId
   * @param version
   * @return Map<String,Object>
   * @date Sep 17, 20159:17:36 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_version_tree_to_do/find/datasource_id_version", method = RequestMethod.GET)
  public Map<String, Object> findByDatasourceIdAndVersion(String datasourceId, String version) {
    LOG.debug("/token/storage_version_tree_to_do/find/datasource_id_version {}", datasourceId,
        version);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    StorageVersionTreeToDo storageVersionTreeToDo =
        storageVersionTreeToDoService.findByDatasourceIdAndVersion(datasourceId, version);
    map.put("obj", storageVersionTreeToDo);
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findByDatasourceIdAndVersion {}", map);
    return map;
  }
}
